package com.tiancheng.trade.order.mapper;

import com.tiancheng.trade.order.bo.RefundOrdersDetailSubmitBO;
import com.tiancheng.trade.order.bo.SubOrderRefundTotalBo;
import com.tiancheng.trade.order.model.IntRefund;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 英文版订单退款持久化
 */
@Repository
public interface IntRefundMapper extends TYBaseMapper<IntRefund> {

    /**
     * 批量保存退款单
     * @param refunds
     * @return
     */
    int saveBatch(List<IntRefund> refunds);

    /**
     * 批量更新退款单
     * @param submitBOS
     * @return
     */
    int updateBatch(List<RefundOrdersDetailSubmitBO> submitBOS);

    /**
     * 查询统计退款的金额和数量
     * @param refundStatus
     * @param startTime
     * @param endTime
     * @return
     */
    Map<String, Long> queryTotal(@Param("refundStatus") List<String> refundStatus,
                                 @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

    /**
     * 分组统计子订单的退款金额
     * @param orderId
     * @param subOrderIds
     * @return
     */
    List<SubOrderRefundTotalBo> sumForSubOrder(@Param("orderId") String orderId, @Param("subOrderIds") String[] subOrderIds);


    /**
     * 分组统计子订单的退款金额,排除本次申请的退款
     * @param orderId 主订单号
     * @param subOrderIds 子订单id集合
     * @param refundId 需要排除的退款申请(退款的paymentId)
     * @return
     */
    List<SubOrderRefundTotalBo> sumForSubOrderExcludeByRefundId(@Param("orderId") String orderId, @Param("subOrderIds") String[] subOrderIds,@Param("refundId") String refundId);
}